/**
 * @author:albert
 */

package com.bkbw.live.battle.business;

import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;

import com.bkbw.live.battle.database.DatabaseManager;
import com.bkbw.live.common.dataproto.ClientToBattleServerPb.BuildPos;
import com.bkbw.live.common.dataproto.CommonMessagePb.Vector3IntPb;
import com.bkbw.live.common.dataproto.EnumConfigPb.BuildType;

public class BuildingObject extends UnitObject {
	
	protected int buildId;
	
	public int getBuildId() {
		return buildId;
	}

	protected Vector3IntPb buildingPos;

	public Vector3IntPb getBuildingPos() {
		return buildingPos;
	}
	
	public Vector3IntPb getVector3IntPbPos() {
		Vector3IntPb.Builder builder = Vector3IntPb.newBuilder();
		builder.setX(buildingPos.getX());
		builder.setZ(buildingPos.getZ());
		return builder.build();
	}
	
	protected int buildType;
	public int getBuildType() {
		return buildType;
	}

	public BuildingObject(int id, GameLogicMap map) {
		super(id, map);
		// TODO Auto-generated constructor stub
	}
	
	public void init(int buildId, Vector3IntPb buildingPos) {
		this.buildId = buildId;
		this.buildingPos = buildingPos;
		buildType = DatabaseManager.getInstance().getBuildTable().getBeanByKey(buildId).getBuildType();
		int width = DatabaseManager.getInstance().getBuildTable().getBeanByKey(buildId).getWidth();
		int height = DatabaseManager.getInstance().getBuildTable().getBeanByKey(buildId).getHeight();
		setPosition(new Vector3D(buildingPos.getX() + width / 2, 0, buildingPos.getZ() + height / 2));
	}

	@Override
	public boolean collision() {
		return true;
	}
	
	@Override
	public void onDead(){
		super.onDead();
		this.map.buildExplode(id);
	}
}
